package com.zty.xiaomi.server.Service.QuartzTask;

import com.zty.xiaomi.server.Entity.Order.OrderList;
import com.zty.xiaomi.server.Entity.Tribunal.Tribunal;
import com.zty.xiaomi.server.Service.Order.OrderServiceImp;
import com.zty.xiaomi.server.Service.Tribunal.TribunalServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class QuartzTask {
    @Autowired
    private OrderServiceImp orderServiceImp;
    @Autowired
    private TribunalServiceImp tribunalServiceImp;

    /**
     * 使用quartz框架
     */


        /**
         * 业务逻辑
         */
        public void reptilian() throws Exception{
//            检查小法庭过期过期时间，请关闭法庭
            List<Tribunal> allTribunal = tribunalServiceImp.getAllTribunal();
            for (Tribunal t:allTribunal
                 ) {
                int create_time = t.getCreate_time();
//                自定义5分钟关闭法庭
                if((new Date().getTime()/1000)-create_time>300){
                    int i = tribunalServiceImp.updateTribunalStatusById(t.getTribunal_id());
                }
            }
            List<OrderList> allOrdeStatusDesc = orderServiceImp.getAllOrdeStatusDesc();
            for (OrderList orderList:allOrdeStatusDesc
                 ) {
                Date parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(orderList.getCreateTime());
                Long time = parse.getTime();
                if(orderList.getStatus()==0&&new Date().getTime()>(time+120000)){
                    System.out.println(time+120000);
                    System.out.println(new Date().getTime());
                  orderServiceImp.UpdateOrder(5,"已取消",orderList.getOrderNo());
                }
                else if(orderList.getStatus()==1){
//                    Date payParse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(orderList.getPaymentTime());
//                    Long payTime = parse.getTime();
//                    if(new Date().getTime()>payTime+120000){
//
//                    }

                }

            }

        }


}
